﻿<UserControl x:Class="Pseudogenerator.Views.WPF.GeneratorsControls.MainControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:Pseudogenerator.Common.ViewModels;assembly=Pseudogenerator.Common.ViewModels"
             xmlns:vw="clr-namespace:Pseudogenerator.Views.WPF.GeneratorsControls"
             xmlns:cv="clr-namespace:Pseudogenerator.Views.WPF.Converters" >
    <UserControl.Resources>

        <DataTemplate DataType="{x:Type vm:MixedCongruentialViewModel}">
            <vw:CongruencialMixto />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:MultiplicativeCongruentialViewModel}">
            <vw:CongruencialMultiplicativo />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:CuadraticCongruentialViewModel}">
            <vw:CongruencialCuadratico />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:FibonacciViewModel}">
            <vw:Fibonacci />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:GreenViewModel}">
            <vw:Green />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:MitchellMooreViewModel}">
            <vw:MitchellMoore />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:MixedViewModel}">
            <vw:Mixto/>
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:TwoSetsMixViewModel}">
            <vw:Mixing1 />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:OneSetMixViewModel}">
            <vw:Mixing2 />
        </DataTemplate>

        <DataTemplate DataType="{x:Type vm:ImporterViewModel}">
            <vw:Importador/>
        </DataTemplate>


        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <cv:NotBoolToVisibilityConverter x:Key="NotBoolToVisibilityConverter"/>
        <cv:CountToVisibilityConverter x:Key="CountToVisibilityConverter"/>
        <cv:BoolToTextConverter x:Key="BoolToTextConverter"/>
        <cv:BoolToBrushConverter x:Key="BoolToBrushConverter" />

        <SolidColorBrush x:Key="ThemeBrush" Color="{Binding SelectedColor, ElementName=ColS, Mode=TwoWay}" />
        <Color x:Key="ThemeForegroundColor">Black</Color>
        <SolidColorBrush x:Key="ThemeForegroundBrush" Color="{StaticResource ThemeForegroundColor}" />
       
       

    </UserControl.Resources>
    <UserControl.Foreground>
        <SolidColorBrush Color="{StaticResource ThemeForegroundColor}" />
    </UserControl.Foreground>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="193" Width="auto" MaxWidth="300"/>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Rectangle VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.RowSpan="2" Height="50" >
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding SelectedColor, ElementName=ColS, Mode=TwoWay}" />
            </Rectangle.Fill>
            <Rectangle.OpacityMask>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.OpacityMask>
        </Rectangle>
        <Rectangle VerticalAlignment="Bottom" Grid.ColumnSpan="3" Grid.RowSpan="2" Height="50">
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding SelectedColor, ElementName=ColS, Mode=TwoWay}" />
            </Rectangle.Fill>
            <Rectangle.OpacityMask>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="1"/>
                    <GradientStop Offset="0"/>
                </LinearGradientBrush>
            </Rectangle.OpacityMask>
        </Rectangle>


        <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Row="1" Height="55" Width="20" x:Name="ColorRec">
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding SelectedColor, ElementName=ColS, Mode=TwoWay}" />
            </Rectangle.Fill>
        </Rectangle>

        <!--<Recursos:ColorSlider Visibility="Hidden" x:Name="ColS" VerticalAlignment="Top" RenderTransformOrigin="0,1" Margin="0,75,0,0" Height="20" Grid.RowSpan="3" SelectedColor="#FFFFCACA" SliderValue="190">
            <Recursos:ColorSlider.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Recursos:ColorSlider.RenderTransform>
        </Recursos:ColorSlider>-->

        <GridSplitter Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,0,0,30" Opacity="0.5" >
            <GridSplitter.OpacityMask>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#00EAF8FF" Offset="0" />
                    <GradientStop Color="{Binding SelectedColor, ElementName=ColS}" Offset="0.139"/>
                    <GradientStop Color="{Binding SelectedColor, ElementName=ColS}" Offset="0.939"/>
                    <GradientStop Color="#00EAF8FF" Offset="1"/>
                </LinearGradientBrush>
            </GridSplitter.OpacityMask>
            <GridSplitter.Background>
                <SolidColorBrush Color="{Binding SelectedColor, ElementName=ColS}" />
            </GridSplitter.Background>
        </GridSplitter>

        <Separator Grid.Column="0" Grid.ColumnSpan="3"
    		VerticalAlignment="Bottom" 
            Height="40"
    		HorizontalAlignment="Left" 
    		FontFamily="Segoe WP Light" 
    		FontSize="26" 
    		Margin="30,0,0,0"/>
        <StackPanel Grid.Row="1" 
                        Margin="30,0,0,0"
                        VerticalAlignment="Top" >

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <Label FontWeight="Bold" Content="METODOS" Foreground="{StaticResource ThemeForegroundBrush}" />

                <ListBox x:Name="WorkSpacesList" 
            			Grid.Row="1"
            			Padding="2"  ItemsSource="{Binding WorkSpaces}" 
            			BorderBrush="{x:Null}" 
            			SelectedIndex="0" Background="{x:Null}">
                    <ListBox.ItemTemplate>
                        <DataTemplate DataType="ListBoxItem">
                            <TextBlock Margin="0,2" Text="{Binding Title}" Foreground="{StaticResource ThemeForegroundBrush}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

            </Grid>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Label FontWeight="Bold" 
                           Content="PRELOADS" 
                           Visibility="{Binding Items.Count, ConverterParameter=0, Converter={StaticResource CountToVisibilityConverter}, ElementName=lstPreloads}" />
                <ListBox x:Name="lstPreloads"  Grid.Row="1"
                             Padding="2" SelectedItem="{Binding SelectedItem.ModeloActual, ElementName=WorkSpacesList, Mode=TwoWay}"
                             BorderBrush="{x:Null}" 
                             Background="{x:Null}"
                             ItemsSource="{Binding SelectedItem.Preloads, ElementName=WorkSpacesList}" FontSize="11" />

            </Grid>
        </StackPanel>
        <Border Grid.Column="2" Grid.Row="1" BorderThickness="0,0,0,0" BorderBrush="#FFC8C8C8" 
                DataContext="{Binding SelectedItem, ElementName=WorkSpacesList}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" MinWidth="265" MaxWidth="350"/>
                    <ColumnDefinition Width="6"/>
                    <ColumnDefinition Width="*" MinWidth="284" />
                </Grid.ColumnDefinitions>
                <GridSplitter Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,0,30" Opacity="0.5" >
                    <GridSplitter.OpacityMask>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#00EAF8FF" Offset="0" />
                            <GradientStop Color="{Binding SelectedColor, ElementName=ColS}" Offset="0.139"/>
                            <GradientStop Color="{Binding SelectedColor, ElementName=ColS}" Offset="0.939"/>
                            <GradientStop Color="#00EAF8FF" Offset="1"/>
                        </LinearGradientBrush>
                    </GridSplitter.OpacityMask>
                    <GridSplitter.Background>
                        <SolidColorBrush Color="{Binding SelectedColor, ElementName=ColS}" />
                    </GridSplitter.Background>
                </GridSplitter>
                <ListBox Grid.Column="2" ItemsSource="{Binding ActionCommands}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Button Content="{Binding Title}" Command="{Binding}" Padding="12,2" Margin="0,0,2,0"  />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <ListBox.Template>
                        <ControlTemplate>
                            <ItemsPresenter />
                        </ControlTemplate>
                    </ListBox.Template>
					<ListBox.ItemContainerStyle>
						 <Style TargetType="{x:Type ListBoxItem}">
        					<Setter Property="Template">
        						<Setter.Value>
        							<ControlTemplate TargetType="{x:Type ListBoxItem}">
        								<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        							</ControlTemplate>
        						</Setter.Value>
        					</Setter>
						</Style>
					</ListBox.ItemContainerStyle>
                </ListBox>
                <Border Grid.Row="1" BorderBrush="#FFCBCBCB" Margin="0,0,0,30">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <StackPanel>
                            <ContentPresenter Content="{Binding}" />

                            <ProgressBar x:Name="WorkProgressBar" Height="20" Margin="0,6" IsIndeterminate="True"
                				Visibility="{Binding InWorkProgress, Converter={StaticResource BooleanToVisibilityConverter}}" />

                            <Label FontWeight="Bold" Content="ERRORES" Foreground="{StaticResource ThemeForegroundBrush}"
                				Visibility="{Binding Items.Count, ConverterParameter=0, Converter={StaticResource CountToVisibilityConverter}, ElementName=lstErrors}" Margin="0,6,0,0" />
                            <ListBox x:Name="lstErrors" ItemsSource="{Binding Errors}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="{x:Null}" Background="{x:Null}" >
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="#FFE60000" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>


                            <Label FontWeight="Bold" Content="RECOMENDACIONES" Foreground="{StaticResource ThemeForegroundBrush}"
                				Visibility="{Binding Items.Count, ConverterParameter=0, Converter={StaticResource CountToVisibilityConverter}, ElementName=lstRecommendations}" Margin="0,6,0,0" />
                            <ListBox x:Name="lstRecommendations" ItemsSource="{Binding Recommendations}"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="{x:Null}" Background="{x:Null}" >
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="#FFE60000" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <Label FontWeight="Bold" Content="PRUEBAS" Margin="0,6,0,0" Foreground="{StaticResource ThemeForegroundBrush}"
                				Visibility="{Binding Items.Count, ConverterParameter=0, Converter={StaticResource CountToVisibilityConverter}, ElementName=lstComprobations}" />
                            <ListBox x:Name="lstComprobations" 
                				ItemsSource="{Binding Tests}" 
                				ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                				BorderBrush="{x:Null}" Background="{x:Null}" >
                                <ListBox.ItemTemplate>
                                    <DataTemplate DataType="ListBoxItem">
                                        <Border Margin="3,0">
                                            <StackPanel>
                                                <TextBlock Text="{Binding Key}" FontSize="11" Foreground="{StaticResource ThemeForegroundBrush}"
                                                           FontWeight="Bold" />
                                                <TextBlock Text="{Binding Value, ConverterParameter=No se puede rechazar la hipotesis:Se puede rechazar la hipotesis, Converter={StaticResource BoolToTextConverter}}" 
                                                           Foreground="{Binding Value, Converter={StaticResource BoolToBrushConverter}}"/>
                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>


                        </StackPanel>
                    </ScrollViewer>
                </Border>

                <DataGrid x:Name="GridResultados" Grid.Column="2" Grid.Row="1" AutoGenerateColumns="False"
                         ItemsSource="{Binding Results}" 
                         Margin="0,0,30,20" ScrollViewer.VerticalScrollBarVisibility="Visible"
                         GridLinesVisibility="None" IsReadOnly="True" SelectionMode="Extended"
                         BorderThickness="0" Background="{x:Null}" RowHeaderWidth="20" 
                         SelectionUnit="CellOrRowHeader" MinRowHeight="20">
                    <DataGrid.AlternatingRowBackground>
                        <SolidColorBrush Opacity=".6" Color="{Binding SelectedColor, ElementName=ColS, Mode=TwoWay}" />
                    </DataGrid.AlternatingRowBackground>
                    <DataGrid.Columns>
                        <DataGridTextColumn Width="*" Header="n" Binding="{Binding n}" />
                        <DataGridTextColumn Width="*" Binding="{Binding Xn}">
                            <DataGridTextColumn.Header>
                                <TextBlock><Run Text="X"/><Run Text=" "/><Run BaselineAlignment="Subscript" Text="n"/></TextBlock>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>

                        <DataGridTextColumn Width="2*" Header="Número Uniforme" Binding="{Binding Uniform}" />

                    </DataGrid.Columns>
                </DataGrid>

            </Grid>
        </Border>
    </Grid>
</UserControl>
